package com.caht.config;

import com.caht.intercept.JWTLoginUserInstantiator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    JWTLoginUserInstantiator jwtLoginUserInstantiator;

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtLoginUserInstantiator)
                // 拦截所有请求
               .addPathPatterns("/**")
                // 排除不需要拦截的请求
               .excludePathPatterns("/user/login/phoneLogin/**"
                       ,"/user/login",
                       "/user/upload/files/**");
    }

    /**
     * 设置静态资源映射吧 例如 图片 视频 音频 登入...
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**")
                .addResourceLocations("file:D:\\HTML_JS\\项目\\博客网\\caht\\caht_servier\\src\\main\\resources\\images\\");
                //.addResourceLocations("classpath:/images/");
    }
}















